﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using WGMClient.Controls;


namespace WGMClient.HelperClasses
{
    public enum ClientState
    {
        BUSY,
        AWAY,
        ONLINE,
        OFFLINE
    }
    public class WGMLocalClient 
    {
        public WGMSvc.WGMMember MemberObject { get; set; }
        public bool IsMainWindow { get; set; }
        private byte[] _imageData;
        public byte[] ImageData 
        {
            get { return _imageData; }
            set { _imageData = value; } 
        }
        public object Tag { get; set; }
        public bool IsOnline { get; set; }
        public bool FirstImageCheckCompleted { get; set; }
        public bool HasMessages { get; set; }
        public TabItem TabObject { get; set; }
        public FontFamily FontFace { get { return new FontFamily(MemberObject.FontFace); } }
        public double FontSize { get { return MemberObject.FontSize; } }
        public bool IsFontItalics { get { return MemberObject.IsFontItalics; } }
        public bool IsFontBold { get { return MemberObject.IsFontBold; } }
        public bool IsFontUnderlined { get { return MemberObject.IsFontUnderlined; } }
        public string Username { get { return MemberObject.Username == null ? "" : MemberObject.Username.Trim().ToLower(); } }
        public Color UserColor { get { return Color.FromArgb(255, (byte)MemberObject.FontColourR, (byte)MemberObject.FontColourG, (byte)MemberObject.FontColourB); } }
        public BackgroundTextBlock AssociatedSelector { get; set; }
        public TabItem AssociatedTab { get; set; }
        public InternalChatControl AssociatedChatControl { get; set; }
        public ClientState OnlineState { get; set; }

        public ImageSource Image
        {
            get
            {
                if (ImageData != null)
                {
                    return HelperClasses.HelperFunctions.GetBitmapFromImage(HelperClasses.HelperFunctions.ByteArrayToImage(ImageData));
                }
                else
                {
                    System.Drawing.Image img = System.Drawing.Image.FromFile(System.Windows.Forms.Application.StartupPath + "\\Images\\blank2.png");
                    return HelperClasses.HelperFunctions.GetBitmapFromImage(img);
                }
            }
        }
        public string DisplayName
        {
            get
            {
                if (MemberObject.DisplayName == null || MemberObject.DisplayName.Trim() == "")
                    return MemberObject.Username;
                else
                    return MemberObject.DisplayName.Trim();
            }
        }
        public string DisplayStatus { get { return MemberObject.DisplayStatus; } }
        public string DisplayString
        {
            get
            {
                string retVal = DisplayName;
                if (MemberObject.DisplayStatus != null && MemberObject.DisplayStatus.Trim() != "")
                {
                    retVal +=" - " + MemberObject.DisplayStatus;
                }
                retVal += " (" + MemberObject.Username + ")";
                return retVal;
            }
        }
        public string ShortDisplayString
        {
            get
            {
                string retVal = DisplayName;
                retVal += " (" + MemberObject.Username + ")";
                return retVal;
            }
        }



    }
}
